<#escape x as x?html>
<div class="appList">
    <ul class="nav nav-tabs nav-fusion">
        <li role="presentation" class="<#if state=="APPLYING">active</#if>" href="#nodeTopolopy" role="tab"
            data-toggle="tab"
            aria-controls="nodeTopolopy" aria-expanded="false" state="APPLYING">
            <div>待审批
            </div>
        </li>
        <li role="presentation" class="<#if state=="PUBLISHED">active</#if>" href="#erDiagram" role="tab"
            data-toggle="tab"
            aria-controls="erDiagram" aria-expanded="false" state="PUBLISHED">
            <div>已发布
            </div>
        </li>
    </ul>
    <div class="box box-solid box-fusion no-shadow no-border">
        <div class="box-header">
            <div class="col-md-7">
                <h3 class="box-title">&nbsp;</h3>
            </div>
            <div class="box-tools">
                <form class="hide" id="fuzzySearchListForm" method="post">
                    <input id="fuzzyField" name="fuzzyField" value="${fuzzyField!''}">
                    <input id="pageIndex" name="pageIndex" value="${page.pageIndex!''}">
                    <input id="pageSize" name="pageSize" value="${page.pageSize!''}">
                    <input id="pagesNum" name="pagesNum" value="${page.pagesNum!''}">
                    <input id="state" name="state" value="${state!''}">
                </form>
                <div class="input-group input-group-fusion pull-right" style="margin-top: 10px;">
                    <input type="text" class="form-control input-sm pull-right search-input"
                           id="fuzzyFieldStr" name="fuzzyFieldStr" placeholder="<@s.message "page.search"/>"
                           value="${fuzzyField!''}">
                    <div class="input-group-btn">
                        <button class="btn btn-sm btn-default search-button"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive no-padding">
            <table class="table table-inner-bordered table-hover with-border-top"
                   data-form-name="应用">
                <thead>
                <th class="col-md-2 col-lg-2">
                    名称
                </th>
                <th class="col-md-1 col-lg-1">
                    版本
                </th>
                <th class="col-md-1 col-lg-1">
                    Context
                </th>
                <th class="col-md-1 col-lg-1">
                    分类
                </th>
                <th class="col-md-1 col-lg-1">
                    订阅数
                </th>
                <th class="col-md-2 col-lg-2">
                    创建时间
                </th>
                <th class="col-md-2 col-lg-2">
                    更新时间
                </th>
                <th class="col-md-2 col-lg-2">
                    操作
                </th>
                </thead>
                <tbody>
                    <#if (page.entities??)&&(page.entities?size>0)>
                        <#list page.entities as record>
                        <tr record-id='${record.id}'>
                            <td>
                            ${(record.name)!''}
                            </td>
                            <td>
                            ${(record.version)!''}
                            </td>
                            <td>
                            ${(record.context)!''}
                            </td>
                            <td>
                            ${(record.category.name)!''}
                            </td>
                            <td>
                            ${(record.subscribeCount)!''}
                            </td>
                            <td>
                            ${(record.createTime)!''}
                            </td>
                            <td>
                            ${(record.updateTime)!''}
                            </td>
                            <td class="popup-close">
                                <#if state == "APPLYING">
                                    <button class="btn btn-default btn-sm pass-publish">
                                        <i class="fa fa-hand-paper-o"> 通过</i>
                                    </button>
                                </#if>
                                <button class="btn btn-default btn-sm reject-publish">
                                    <i class="fa fa-thumbs-down"> 打回</i>
                                </button>
                            </td>
                        </tr>
                        </#list>
                    </#if>
                </tbody>
            </table>
        </div><!-- /.box-body -->
        <div class="box-footer no-border clearfix">
            <@y.htmlPaginationOverview/>
        </div>
    </div>
</div><!-- /.box -->
    <@y.htmlModal type="save" width="750px"/>
<script>
    context.call([
        "list",
        "tools",
        "core"
    ], function (list, tools, core) {
        list.initFuzzySearchList("/sys/approve", {
            recordIdName: "record-id",
            actionEdit: "record-id",
            targetSelector: ".appList",
            urlList: "list",
            searchFormSelector: "#fuzzySearchListForm",
            recordFormSelector: "#recordForm",
            recordAttr: "record-attr",
            recordAttr2: "record-attr2"
        });

        function getRecordId() {
            return $(this).closest("[record-id]").attr("record-id");
        }

        $(".pass-publish").each(function () {
            $(this).on("click", function (e) {
                var appId = getRecordId.call($(this));
                tools.confirm({
                    message: "通过应用发布?",
                    title: "应用发布审批",
                    callback: function (result) {
                        if (result) {
                            $.ajax({
                                url: "/sys/approve/passPublish?id=" + appId,
                                success: function (msg) {
                                    if (core.message(msg)) {
                                        core.loadContent("/sys/approve/list?state=${state}");
                                    }
                                    tools.notifyMini({message: "应用已发布"});
                                }
                            })
                        }
                    }
                });
            });
        });

        $(".reject-publish").each(function () {
            $(this).on("click", function (e) {
                var appId = getRecordId.call($(this));
                tools.confirm({
                    message: "打回应用发布?",
                    title: "应用发布审批",
                    callback: function (result) {
                        if (result) {
                            $.ajax({
                                url: "/sys/approve/rejectPublish?id=" + appId,
                                success: function (msg) {
                                    if (core.message(msg)) {
                                        core.loadContent("/sys/approve/list?state=${state}");
                                    }
                                    tools.notifyMini({message: "应用已打回"});
                                }
                            })
                        }
                    }
                });
            });
        });

        $('li[aria-controls]').on('shown.bs.tab', function (e) {
            $("#state").val($(this).attr("state"));
            $(".search-button").trigger("click");
        });
    });
</script>
</#escape>